package pATT.core.visual;

import java.awt.Dimension;
import java.awt.HeadlessException;
import java.awt.Toolkit;
import java.util.Enumeration;

import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;

import pATT.core.Instances;





public class UserProfilingUI extends JFrame {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private PreProcessPanel preProcessPanel = null;
	private VisualizePanel visualizePanel = null;
	private ProfilingPanel profilingPanel = null;
	private DecisionMakingPanel decisionMakingPanel = null; 
	
	private JPanel jContentPane = null;
	private JEditorPane jLogEditorPane = null;
	private JScrollPane jScrollPane = null;
	private JTabbedPane jTabbedPane = null;
	public static UserProfilingUI eINSTANCE = new UserProfilingUI();
	
	private UserProfilingUI() throws HeadlessException {
		super();
		initialize();
	}
	
	public static void createInstance(){
			eINSTANCE = new UserProfilingUI();
	}   
	/**
	 * This method initializes jLogEditorPane	
	 * 	
	 * @return javax.swing.JEditorPane	
	 */
	private JEditorPane getJLogEditorPane() {
		if (jLogEditorPane == null) {
			jLogEditorPane = new JEditorPane();
			jLogEditorPane.setText("");
			jLogEditorPane.setBounds(new java.awt.Rectangle(0,0,772,105));
			jLogEditorPane.setEditable(false);	
		}
		return jLogEditorPane;
	}
	
	public static void main(String[] args) {
		UserProfilingUI.eINSTANCE.show();
	}
	
	/**
	 * This method initializes jScrollPane	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getJScrollPane() {
		if (jScrollPane == null) {
			jScrollPane = new JScrollPane();
			jScrollPane.setBounds(new java.awt.Rectangle(3,426,782,135));
			jScrollPane.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.blue,1), "Log", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Microsoft Sans Serif", java.awt.Font.PLAIN, 11), java.awt.Color.blue));
			jScrollPane.setBackground(java.awt.SystemColor.control);
			jScrollPane.setViewportView(getJLogEditorPane());
		}
		return jScrollPane;
	}
	
	/**
	 * This method initializes jTabbedPane	
	 * 	
	 * @return javax.swing.JTabbedPane	
	 */
	private JTabbedPane getJTabbedPane() {
		if (jTabbedPane == null) {
			jTabbedPane = new JTabbedPane();
			jTabbedPane.setBounds(new java.awt.Rectangle(2,3,790,421));
			jTabbedPane.setBackground(java.awt.SystemColor.control);
			jTabbedPane.setFont(new java.awt.Font("Microsoft Sans Serif", java.awt.Font.PLAIN, 11));
			jTabbedPane.addTab("Pre-Process", null, this.preProcessPanel.getJPreProcessPanel(), null);
			jTabbedPane.addTab("Profiling", null, this.profilingPanel.getJPanel4(), null);
			jTabbedPane.addTab("Decision Making", null, this.decisionMakingPanel.getJDMPanel(), null);
			jTabbedPane.addTab("Visualize", null, this.visualizePanel.getJVisualizePanel(), null);
			
			jTabbedPane.setSelectedIndex(0);
			jTabbedPane.setEnabledAt(1, false);
			jTabbedPane.setEnabledAt(2, true);
			jTabbedPane.setEnabledAt(3, true);
			
		}
		return jTabbedPane;
	}
	
	
	
	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		
		this.preProcessPanel = new PreProcessPanel();
		this.profilingPanel = new ProfilingPanel();
		this.decisionMakingPanel = new DecisionMakingPanel(); 
		this.visualizePanel = new VisualizePanel();
		
		this.setResizable(false);
		
//		contTable = 0;
		Dimension pantalla = Toolkit.getDefaultToolkit().getScreenSize();
//		int x = pantalla.width;
//		int y = pantalla.height-30;
		int x = 800;
		int y = 600;

		this.setSize(new java.awt.Dimension(x,y));
		
//		Dimension pantalla = Toolkit.getDefaultToolkit().getScreenSize();
		Dimension freim = this.getSize();
		if (pantalla.width < freim.width){
			freim.width = pantalla.width;
		}
		if (pantalla.height < freim.height) {
			freim.height = pantalla.height;
		}
		this.setLocation((pantalla.width-freim.width)/2,(pantalla.height-freim.height)/2);

		this.setBackground(java.awt.SystemColor.control);
		this.setContentPane(getJContentPane());
		this.setTitle("PATT");
	}
	
	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.setBackground(java.awt.SystemColor.control);
			jContentPane.add(getJScrollPane(), null);
			jContentPane.add(getJTabbedPane(), null);
		}
		return jContentPane;
	}
	
	
	/**
	 * Metodo para visualizar la informacion de la relacion en la pantalla de pre-proceso
	 * 
	 * @param nameRelation 
	 * @param numInstance
	 * @param numAttribute
	 * 
	 * */
	public void updateRelationInfo(String nameRelation,int numInstances, int numAttributes){
		this.preProcessPanel.updateRelationInfo(nameRelation,numInstances,numAttributes);
	}
	
	public void setMessage(String message){
		String Text=jLogEditorPane.getText();
		getJLogEditorPane().setText(Text+message);
		getJLogEditorPane().setSelectionEnd(1);
		
	}
	
	
	public void clearLog() {
		getJLogEditorPane().setText("");
		
	}
	
	
	/**Se visualiza o no el panel de Profiling */	
	public void OpenFilePreProcess(boolean bol){
		if(!getProfilingPanel().isEmpty()){
			getJTabbedPane().setEnabledAt(1, bol);
		}
		
//		this.profilingPanel.getJPanel4().setEnabled(true);
//		this.decisionMakingPanel.getJDMPanel().setEnabled(true);
		
	}
	
	
	public void updateAttributesInfo(Instances inUse) {
		this.preProcessPanel.updateAttributesInfo(inUse);
		
	}

	public void updateAttributesInfo(Enumeration listInUse) {
		this.preProcessPanel.updateAttributesInfo(listInUse);
		
	}

	public ProfilingPanel getProfilingPanel() {
		return profilingPanel;
	}

	public VisualizePanel getVisualizePanel() {
		return visualizePanel;
	}

	public void updateVisualizer() {
		getVisualizePanel().getJChooserButton().setEnabled(true);
		
	}
	
}  
//@jve:decl-index=0:visual-constraint="10,10"